//
// Created by haoy on 2017/6/20.
//

#ifndef RTC_XSWITCH2_ULPFEC_DECODER_HPP
#define RTC_XSWITCH2_ULPFEC_DECODER_HPP

#include <map>
#include <cstdint>
#include <list>
#include <map>
#include <memory>

#include "codecs.hpp"
#include "rtp/rtp_factory.hpp"
#include "rtp/rtp_map.hpp"
#include "rtp/rtp_packet.hpp"

class UlpfecDecoder {
    static constexpr int WINDOW_SIZE = 64;
public:
    UlpfecDecoder(RtpFactory* factory, rtc_codecs_t* codecs);
    ~UlpfecDecoder();

    void add(std::shared_ptr<RtpPacket> packet);
    int recover(std::list<std::shared_ptr<RtpPacket>>& recovered_packets);
private:
    RtpFactory* rtp_factory_ = nullptr;
    rtc_codecs_t* codecs_ = nullptr;
    std::map<uint16_t, std::shared_ptr<RtpPacket>> media_packets_;
    std::map<uint16_t, std::shared_ptr<RtpPacket>> fec_packets_;
    uint16_t head_seq_ = 0;
    uint16_t tail_seq_ = 0;
    bool debug_ = false;
};


#endif //RTC_XSWITCH2_ULPFEC_DECODER_HPP
